package com.platform.api;

import com.platform.annotation.IgnoreAuth;
import com.platform.annotation.LoginUser;
import com.platform.entity.ApiClientMessageEntity;
import com.platform.entity.ApiEmceeAdPositionEntity;
import com.platform.entity.ApiStandingsTypeEntity;
import com.platform.entity.UserVo;
import com.platform.service.ApiClientMessageService;
import com.platform.service.impl.ApiEmceeAdPositionServiceImpl;
import com.platform.service.impl.ApiEmceeAdServiceImpl;
import com.platform.service.impl.ApiStandingsServiceImpl;
import com.platform.service.impl.ApiStandingsTypeServiceImpl;
import com.platform.util.ApiBaseAction;
import com.platform.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 作者: @author  <br>
 * 时间: 2019-03-15  <br>
 * 描述: ApiEmceeAdController <br>
 */
@Api(tags = "婚礼小程序接口")
@RestController
@RequestMapping("/api/emcee/Ad")
public class ApiEmceeAdController extends ApiBaseAction {

    @Autowired
    private ApiEmceeAdServiceImpl emceeAdService;
    @Autowired
    private ApiStandingsServiceImpl standingsService;
    @Autowired
    private ApiStandingsTypeServiceImpl standingsTypeService;
    @Autowired
    private ApiEmceeAdPositionServiceImpl emceeAdPositionService;
    @Autowired
    private ApiClientMessageService apiClientMessageService;

    /**
     * 获取展示类内容
     */
    @ApiOperation(value = "获取展示类内容", response = Map.class)
    @GetMapping("emceeAdList")
    @IgnoreAuth
    public R emceeAdList(@RequestParam("code")String code,
                         @RequestParam("createUser")long createUser) {
        ApiEmceeAdPositionEntity apiEmceeAdPositionEntity = emceeAdPositionService.queryByCodeAndUser(code, createUser);
        if(apiEmceeAdPositionEntity == null){
            return R.ok().put("list","");
        }
        int adpId = apiEmceeAdPositionEntity.getId();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("adPositionId",adpId);
        param.put("createUser", createUser);
        return R.ok().put("list",emceeAdService.queryList(param));
    }

    /**
     * 获取展示客户现场
     */
    @ApiOperation(value = "获取展示客户现场", response = Map.class)
    @GetMapping("standingsList")
    @IgnoreAuth
    public R standingsList(@RequestParam("code")String code,
                           @RequestParam("createUser")long createUser) {

        ApiStandingsTypeEntity apiStandingsTypeEntity = standingsTypeService.queryByCodeAndUser(code, createUser);
        if(apiStandingsTypeEntity == null){
            return R.ok().put("list","");
        }
        int typeId = apiStandingsTypeEntity.getId();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("typeId",typeId);
        param.put("createUser", createUser);
        return R.ok().put("list",standingsService.queryList(param));
    }

    /**
     * 客户现场类别
     */
    @ApiOperation(value = "获取客户现场类别", response = Map.class)
    @GetMapping("standingsTypeList")
    @IgnoreAuth
    public R standingsTypeList(@RequestParam("createUser")long createUser){
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("createUser", createUser);
        return R.ok().put("list",standingsTypeService.queryList(param));
    }

    /**
     * 客户现场类别
     */
    @ApiOperation(value = "获取展示类内容类别", response = Map.class)
    @GetMapping("emceeAdPositionList")
    @IgnoreAuth
    public R emceeAdPositionList(@RequestParam("createUser")long createUser){
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("createUser", createUser);
        return R.ok().put("list",emceeAdPositionService.queryList(param));
    }

    /**
     * 保存
     */
    @ApiOperation(value = "提交客户留言", response = Map.class)
    @PostMapping("saveClientMessage")
    public R saveClientMessage(@LoginUser UserVo loginUser,
                               @RequestBody ApiClientMessageEntity clientMessage) {
        Long userId = loginUser.getUserId();
        clientMessage.setSubmitUser(userId.intValue());
        clientMessage.setSubmitTime(new Date());
        apiClientMessageService.save(clientMessage);
        return R.ok();
    }
}